package Niuke.试题广场;

import java.util.PriorityQueue;

/**
 * @author: leiwenkang
 * @date: 2020/6/13
 * @time: 14:27
 */
public class 牛牛算数 {
    public static void main(String[] args) {
        int[] array = {1, 2, 3, 3, 4};
        System.out.println(solve(5, 70, array));
    }

    public static long solve (int n, int c, int[] a) {
        // write code here
        PriorityQueue<Integer> que=new PriorityQueue();
        for(int i:a){
            que.add(i);
        }
        long sum=0;
        while(que.size()>=2){
            int d=que.poll();
            int b=que.poll();
            que.add(d+b);
            sum+=(d+b)*c;
        }
        return sum;
    }
}
